package com.eascs.admin.o2o.loan.service;


import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.eascs.admin.common.service.BaseSevice;
import com.eascs.admin.o2o.loan.dao.BCRecommendationDao;
import com.eascs.admin.o2o.loan.entity.BCRecommendationEntity;
import com.eascs.admin.o2o.loan.entity.BCRecommendationUpdateRecord;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.workflow.common.vo.ModelResult;

@Service
public class BCRecommendationService extends BaseSevice{
	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private BCRecommendationDao recommendationDao;
	
	public ModelResult<Integer> insertBCRecommendation(BCRecommendationEntity recommendationEntity) {
		ModelResult<Integer> modelResult=new ModelResult<Integer>();
		try {
			int result=recommendationDao.insertBCRecommendation(recommendationEntity);
			modelResult.setModel(result);
		} catch (Exception e) {
			 logger.error("bc.recommendation.insert.error :", e.getMessage());
			 modelResult.withError("bc.recommendation.insert.error", "中行推荐函新增报错:"+e.getMessage());
			 return modelResult;
		}
		return modelResult;
	}
	
	
	public ModelResult<Integer> updateBCRecommendation(BCRecommendationEntity recommendationEntity) {
		ModelResult<Integer> modelResult=new ModelResult<Integer>();
		try {
			int result=recommendationDao.updateBCRecommendation(recommendationEntity);
			modelResult.setModel(result);
		} catch (Exception e) {
			 logger.error("bc.recommendation.update.error :", e.getMessage());
			 modelResult.withError("bc.recommendation.update.error", "中行推荐函修改报错:"+e.getMessage());
			 return modelResult;
		}
		return modelResult;
	}
	
	public ModelResult<BCRecommendationEntity> queryBCRecommendationByLoanNo(String loanNo) {
		ModelResult<BCRecommendationEntity> modelResult=new ModelResult<BCRecommendationEntity>();
		try {
			if (StringUtils.isBlank(loanNo)) {
				logger.error("bc.recommendation.query.error: loanNo is null");
				modelResult.withError("bc.recommendation.query.error", "loanNo不能为空");
				return modelResult;
			}
			BCRecommendationEntity result=recommendationDao.queryBCRecommendationByLoanNo(loanNo);
			modelResult.setModel(result);
		} catch (Exception e) {
			 logger.error("bc.recommendation.query.error :", e.getMessage());
			 modelResult.withError("bc.recommendation.query.error", "中行推荐函查询报错:"+e.getMessage());
			 return modelResult;
		}
		return modelResult;
	}
	
	
	public ModelResult<Integer> insertBCRecommendationRecord(BCRecommendationUpdateRecord insertBCRecommendationRecord) {
		ModelResult<Integer> modelResult=new ModelResult<Integer>();
		try {
			int result=recommendationDao.insertBCRecommendationRecord(insertBCRecommendationRecord);
			modelResult.setModel(result);
		} catch (Exception e) {
			 logger.error("bc.recommendation.updaterecord.insert.error :", e.getMessage());
			 modelResult.withError("bc.recommendation.updaterecord.insert.error", "中行推荐函修改记录报错:"+e.getMessage());
			 return modelResult;
		}
		return modelResult;
	}
}
